package cn.weakup.thread.impl;

import java.util.concurrent.Callable;

/**
 * @author Dawn
 * @version 1.0.0
 * @desc 在java中线程的实现方式
 * @date 2022/5/4
 */
public class ThreadImpl {
    public static void main(String[] args) throws Exception {
        for (int i = 0; i < 3; i++) {
            new TestThread().start();
            new TestRunnable().run();
            new TestCallable().call();
        }

    }


    /**
     * 方法一：继承thread 重写run方法
     */
    static class TestThread extends Thread {

        @Override
        public void run() {
            System.out.println("TestThread==>" + Thread.currentThread().getName());
        }
    }

    /**
     * 方法二：实现Runnable接口
     */
    static class TestRunnable implements Runnable {

        @Override
        public void run() {
            System.out.println("TestRunnable==>" + Thread.currentThread().getName());
        }
    }

    /**
     * 方法三：实现Callable接口 可用于接收返回值
     */
    static class TestCallable implements Callable<String> {

        @Override
        public String call() throws Exception {
            System.out.println("TestCallable==>" + Thread.currentThread().getName());
            return null;
        }
    }
}
